home *** CD-ROM | disk | FTP | other *** search
- Path: isonews.bbn.hp.com!hpbblb!news
- From: Matthias Dittrich <matti>
- Newsgroups: comp.lang.c
- Subject: Re: strange behaviour of doubles
- Date: 4 Mar 1996 12:46:25 GMT
- Organization: Hewlett-Packard Co.
- Message-ID: <4heon1$6q7@hpbblb.bbn.hp.com>
- References: <1996Mar4.014052.6236@dcs.warwick.ac.uk>
- NNTP-Posting-Host: trabant.bbn.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
- X-URL: news:1996Mar4.014052.6236@dcs.warwick.ac.uk
-
- D.C.Molero@dcs.warwick.ac.uk (Daniel Castillo Molero) wrote:
- >
- >Dear readers,
- >Can anybody explain to me why the behaviour of the following little
- >program is not the expected one ??
- >It is supposed to read from std input pairs of doubles and print them,
- >until 0.0 is input.
- >The strange thing is that it doesn't print the input number, e.g. when
- >I input 1.0 1.0 it prints 0.0078125 0.0078125
- >I will appreciate very much any help.
- >
- >
- >#include <stdio.h>
- >#include <stdlib.h>
- >
- >main() {
- >double x, y;
- >scanf("%g", &x);
- >while (x != 0.0) {
- > scanf("%g", &y);
- Use format "%lg" because you have specified to read a float here !!
-
- > printf("%g %g\n", x, y);
- If you are printing before reading in the value of x, there is an undefined
- value on the stack.
-
- > scanf("%g", &x);
- Format see above.
-
- >}
- >return(0);
- >}
- >--
- >* Daniel Castillo. danmol@dcs.warwick.ac.uk *
- >
- >
- Good luck,
- Matthias
-
-